﻿#pragma once
#include <vector>
/***************************************************************************************************
*
*			the circular buffer base on std vector
***************************************************************************************************/


template<class T>
class circular_buffer
{
public:
	using value_type = T;
	using iterator = typename std::vector<value_type>::iterator;

public:
	circular_buffer() :circular_buffer_vec() {}

	iterator begin() { return circular_buffer_vec.begin(); }

	iterator end() { return circular_buffer_vec.end(); }

	bool empty() { return circular_buffer_vec.empty(); }

	bool full() { return circular_buffer_vec.capacity() == circular_buffer_vec.size(); }

	void push_back(value_type value) 
	{
		if (!full())
			circular_buffer_vec.emplace_back(value);
	}

	value_type front() { return !empty() ? *circular_buffer_vec.begin() : value_type(); }


	void pop_front()
	{
		if (!empty())
		{
			circular_buffer_vec.erase(circular_buffer_vec.begin());
		}
	}

	void reset_size(int size)
	{
		circular_buffer_vec.reserve(size);
	}

	size_t size() { return circular_buffer_vec.size(); }

private:
	std::vector<value_type> circular_buffer_vec;
};